package com.gxjc.dao.bean;

import java.util.List;

import org.hibernate.Session;

import com.gxjc.model.User;

public class UserDao extends BaseDao {
	public List<User> getAll() {
		String hql = "FROM User";
		return getSession().createQuery(hql).list();
	}
	public void save(User user) {
		Session session = getSession();
		session.save(user);
		session.getTransaction().commit();
		session.close();
	}
	public void update(User user) {
		Session session = getSession();
		session.update(user);
		session.getTransaction().commit();
		session.close();
	}
	
	public void delete(int id) {
		getSession().delete(getSession().get(User.class,id));
	}
	
	public User getUserById(int id) {
		return (User)getSession().get(User.class,id);
	}
	
	public List<User> getUserBySql(String hql) {
		return getSession().createQuery(hql).list();
	}
}
